Skip to content

fix(android-e2e): wait for the Home/Recents surface change before pixel assertions - #4716

Merged
thymikee merged 4 commits into
mainfrom
t3/android-transition-wait
Nov 19, 2026
Merged

thymikee merged 4 commits into
mainfrom
t3/android-transition-wait

Conversation

@thymikee

@thymikee thymikee commented Nov 18, 2026 •

Copy link
Copy Markdown
Member

Summary

Closes #4710.

The Android emulator smoke scenario (smoke:automation-system) took one screenshot immediately after home and after app-switcher and asserted it differed from the previous surface. When the launcher or the Recents transition had not drawn yet, the capture still showed the previous surface, so the identical-image assertion failed intermittently on main and on unrelated PRs (e.g. #4297).

assertHomeAndRecentsRestoration now waits at that observation seam with the bounded waitForSurfaceChange helper (test/integration/android-emulator-e2e/live-surface-transition.ts, same contract as the existing waitForImeWindow): re-capture every 250 ms until the screenshot differs from the baseline, within a 10 s deadline. Each attempt removes and overwrites the artifact, so the final observed image is kept and a failed capture cannot leave a stale one; the default capture is bounded by the remaining deadline (5 s per-attempt cap, failure evidence deferred to the deadline verdict); a capture resolving after the deadline is rejected as late. The Home foreground-package proof and both assertFilesDiffer pixel comparisons are retained unchanged; the wait fails at the deadline if navigation never produces the change. No fixed blanket sleep, no smoke-test retry, no weakened assertion, no production change, no workflow/runner change (#4712 untouched).

Regression coverage runs the lane through the harness entry: createAndroidLiveHarness({ runCli }) (the harness-owned runner injection) + createAndroidLiveAssertions(harness) + createHomeAndRecentsRestorationScenario(steps) executed via runScenario, with a scripted CLI double that observes and enforces the forwarded capture timeout. Tests cover: delayed Home/Recents captures passing only via the wait (single-capture route fails them), timeout negatives at the 10 s deadline, wedged captures cut at the forwarded remaining timeout (removing the timeoutMs from the default capture fails these tests — verified by mutant), and late-observation rejection.

Validation

  • Final head: 55f5b877e31a676107f47d5457d2d5179a317b83 after pnpm install --frozen-lockfile && pnpm build. pnpm check:affected --run --head 55f5b877e31a676107f47d5457d2d5179a317b83 (receipt .tmp/validation/run-S084nc, exactCommit=true): format, lint, typecheck, fallow, layering, di-seams, build, package, integration-node, macos-coverage, vitest-related all passed; unit passed 20613/20627 with only known host-load 5 s-timeout flakes in scripts/__tests__/release-publish.test.ts / test/repo-guards/release-assets.test.ts (pass solo; same failures on unchanged origin/main under the same host load). Focused: 27/27 across the four android-emulator-e2e suites (9 new tests), live-device-e2e-runtime 14/14; pnpm typecheck, pnpm format, oxlint, fallow audit clean.
  • Hosted Android validation: workflow run 44406428798 at head_sha 55f5b877e31a676107f47d5457d2d5179a317b83 — the Smoke Tests job passed on the initial run plus ten consecutive reruns at the unchanged head (11 executions, all success; job attempts 135162841640, 135166033700, 135169807283, 135173730913, 135177643973, 135180726313, 135184007531, 135187535422, 135190285281, 135193942664, 135197493388). Per-attempt logs + android-artifacts retained (/tmp/ad-smoke-55f5b877/01..11): each shows ✔ live Android emulator fixture E2E pass 1/fail 0, step-history capture Android Home surface (attempt N) and capture Android Recents surface (attempt N) status 0 (both transition waits passed their pixel comparisons; three distinct PNG md5s per attempt), and home-recents-restoration in coverage-report.json (fixture restoration). This satisfies Android emulator smoke: Home and Recents screenshot comparisons fail intermittently #4710's ten-consecutive-passes criterion at the final head.

…el assertions

The Android smoke scenario captured one screenshot immediately after home and
app-switcher and asserted it differed from the previous surface. When the
launcher or Recents transition had not drawn yet, the capture still showed the
previous surface and the identical-image assertion failed intermittently on
main and unrelated PRs (#4710).

assertHomeAndRecentsRestoration now polls screenshots through the new
waitForSurfaceChange helper at that seam: each attempt overwrites the artifact
so the final observed image is kept, the Home foreground-package proof and both
assertFilesDiffer pixel comparisons are retained, and the wait fails at its
10s deadline if navigation never produces the change. No fixed sleep, no
retry of the smoke test, no weakened assertion.

live-surface-transition.test.ts pins the contract deterministically under
fake timers: a delayed transition satisfies the wait only once a capture
differs (keeping that final image), transient capture failures are retried,
and a surface that never changes (or captures that keep failing) fails at the
deadline with the last observation.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@github-actions

github-actions Bot commented Nov 18, 2026 •

Copy link
Copy Markdown
Contributor

Size Report

Metric Base Current Diff
Installed (including dependencies) 6.39 MB 6.39 MB 0 B
Package (unpacked) 6.39 MB 6.39 MB 0 B
Package (download) 1.94 MB 1.94 MB +3 B

Startup median (7 runs, lower is better):

Scenario Base Current Diff
CLI --version 33.5 ms 32.5 ms -0.9 ms
CLI --help 76.0 ms 73.1 ms -2.9 ms

@thymikee

Copy link
Copy Markdown
Member Author

The review of 13b6f71 found two issues that need attention before merge.

Could the regression exercise both Home and Recents through the scenario harness with delayed captures? The new cases call the helper directly, so restoring the old single captures in the scenario leaves them passing while the race returns. Please show that the regression fails with the old route. Test

The changed Android smoke path has no completed hosted run at the final head, and issue #4710 requires ten consecutive passes at an unchanged head. Please run the hosted scenario through Home, Recents, and fixture restoration ten times at the final head, retaining logs and artifacts that identify the head and prove both screenshot comparisons and restoration. Scenario

Not blocking: You can take or leave a change to pass the remaining deadline through screenshot capture, bound or defer failure evidence, reject late observations, and cover slow capture and failure paths.

The Android Smoke Tests job, which runs this scenario, was still running when I posted. No conflicts are known. Before merge, protect the scenario wiring, address the deadline overrun, and obtain the exact-head Android smoke evidence.

@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 13b6f71. The verdict and the full list are in the summary comment.

…d bound captures by the wait deadline

Review of #4716: the helper-level tests alone would still pass if the scenario
went back to single captures, so the regression now also runs
assertHomeAndRecentsRestoration through the real harness wiring (context runCli
override) against a scripted device whose first Home capture still shows the
fixture and whose first Recents capture still shows Home. The scenario passes
only via the polling wait, and fails at the 10s deadline when either surface
never changes — a single-capture route fails both pixel comparisons on the
first identical capture.

waitForSurfaceChange now passes the remaining deadline into each capture
(capped at 5s, allowFailure so per-attempt failure evidence stays deferred to
the deadline verdict), removes the stale artifact before each attempt, and
rejects a capture that resolves after the deadline as a late observation.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@apex-sentinel-staging

This comment has been minimized.

@apex-sentinel-staging apex-sentinel-staging Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Apex Sentinel: 1 new finding on 8516300. The verdict and the full list are in the summary comment.

@thymikee

Copy link
Copy Markdown
Member Author

At 8516300, the default capture now forwards the remaining timeout, fixing the issue raised in the earlier review, but the regression coverage and hosted validation still need work. No conflicts are known.

Could the deadline test exercise the default capture through the harness with a CLI double that observes and enforces the forwarded timeout? The current test injects a capture that rejects itself, so removing the timeout from the default capture would leave it passing and allow the long screenshot wait to return. Please verify that removing the timeout makes the test fail.

The hosted run was still in progress, so ten consecutive hosted Android Smoke Tests passes at this head are not yet established. Please run the hosted Android smoke lane ten consecutive times at the unchanged head and retain links and output showing that smoke:automation-system reaches both Home and Recents transition waits and passes their pixel comparisons.

Could the test use the harness-owned runCli injection to run the registered scenario with a scripted device, keeping timeout handling at the screenshot observation boundary? That would require exposing or constructing the Android harness with its existing runner injection, then deleting the context override and scenario-internal export.

The open scenario runner thread still applies; no lower-priority threads still apply. The capture timeout thread no longer applies because the default capture forwards the bounded timeout.

Smoke Tests, which runs both changed transitions, was still running when I posted. Before merge, add a regression that detects removal of the default capture timeout and obtain ten consecutive hosted Android smoke passes at the exact head.

@thymikee

Copy link
Copy Markdown
Member Author

Both blocking findings are addressed at 8516300c956fa37f99a2a9a27a35fdbe9a28f9a3.

1. Scenario-level regression. New test/integration/android-emulator-e2e/live-automation-scenario.test.ts drives the real assertHomeAndRecentsRestoration through the scenario harness (shared createLiveDeviceHarness wiring: commonFlags, step history, command/behavior evidence) using a new per-context LiveDeviceContext.runCli override that scripts the device: the first Home capture still returns the fixture image and the first Recents capture still returns Home. The scenario then passes only through the polling wait (step history shows capture Android Home surface (attempt 2) / capture Android Recents surface (attempt 2)), and two negatives fail at the 10s deadline when either surface never changes. Red-on-old-route proof: with the two wait calls temporarily replaced by single capturePng calls (the pre-#4716 route), all three tests in that file fail with Android Home should replace fixture pixels / Android Recents should differ from Home pixels; with the wait restored, 9/9 pass across the two new test files.

2. Deadline overrun (taken). waitForSurfaceChange now passes the remaining deadline into each capture (capped at 5s per attempt, allowFailure so per-attempt failure evidence stays deferred to the deadline verdict), removes the stale artifact before each attempt, and rejects a capture that resolves after the deadline as a late observation. New deterministic tests: no capture outlives the remaining deadline and a capture that resolves after the deadline is rejected as a late observation.

3. Ten consecutive hosted Android smoke passes at the final head. Workflow run 44388138478 (android.yml, event pull_request, head_sha 8516300c956fa37f99a2a9a27a35fdbe9a28f9a3): the initial Smoke Tests job plus ten reruns of the same job at the unchanged head, all success — 11 consecutive executions, 10 of them reruns:

# job attempt conclusion
1 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135098193369 success
2 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135103408040 success
3 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135106651054 success
4 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135111121813 success
5 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135115570823 success
6 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135119719184 success
7 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135123602783 success
8 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135127181860 success
9 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135130796666 success
10 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135133950196 success
11 https://github.com/callstack/agent-device/actions/runs/44388138478/job/135137594890 success

Each attempt's full job log and android-artifacts download are retained (per-attempt proof.txt plus logs/artifacts, kept locally at /tmp/ad-smoke-4716/01..11). Every proof shows: ✔ live Android emulator fixture E2E with pass 1 / fail 0; step-history screenshot steps capture Android fixture foreground, capture Android Home surface (attempt N), capture Android Recents surface (attempt N) (the attempt suffix proves the new wait route is live in CI); three distinct md5s for foreground.png/home.png/recents.png (both pixel comparisons passed); and home-recents-restoration present in coverage-report.json (fixture restoration after Home/Recents).

Local gates at 8516300c95: pnpm check:affected --run --head 8516300c956fa37f99a2a9a27a35fdbe9a28f9a3 (receipt .tmp/validation/run-6RCKeL, exactCommit=true) — every gate passed except the unit suite's known host-load flake in scripts/__tests__/release-publish.test.ts (5s timeout; passes solo and also fails on unchanged origin/main under the same load); 20616/20627 unit tests passed, including all 9 new tests. Focused runs: 9/9 across the two new files plus the neighboring harness suites; pnpm typecheck, pnpm format, oxlint clean.

@thymikee thymikee added the ready-for-human Valid work that needs human implementation, judgment, or maintainer merge label Nov 18, 2026
@thymikee

Copy link
Copy Markdown
Member Author

Thanks. I checked both against 8516300, and my last review missed them:

The per-attempt deadline and the late-observation rejection are covered by their own tests. All checks pass, and there are no conflicts. This is ready for review.

thymikee and others added 2 commits November 18, 2026 22:52
…try and pin the capture timeout

Review of #4716 at 8516300: the scenario test faked the route via a context
runCli override and a direct internal export. The Android harness is now
constructible with its existing runner injection (createAndroidLiveHarness),
the assertion helpers are bound per harness (createAndroidLiveAssertions), and
the Home/Recents lane runs as a registered scenario (runScenario) with steps
passed in — the context override and the scenario-internal export are gone.

The scripted CLI double observes and enforces the forwarded step timeout like a
real runner: captures finish after 60s unless the forwarded timeoutMs kills
them. With the timeout, the wedged-capture test fails at the 10s wait deadline
with 'capture N failed' and the recorded timeouts show the remaining deadline
(capped at 5s, shrinking); removing timeoutMs from the default capture makes
both scenario tests fail (verified locally), so the regression detects the
removal. waitForSurfaceChange takes the bound capturePng so the default
capture's timeout reaches the harness's CLI runner.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
fallow flags automationScenarioSteps as an unused export; only the scenario
module consumes it as the default steps parameter.

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
@apex-sentinel-staging

Copy link
Copy Markdown

Apex Sentinel · ✅ Approve · review of 55f5b87

Since the review of 8516300: 0 new · 0 still open · 1 no longer raised

No open findings.

1 finding below minor hidden (user_settings.min_severity).

Reviewed with this repository's own Sentinel configuration (6e18ea334968).

💬 Talking to Sentinel

In a finding's thread, reply with:

Command What it does
@apex-sentinel-staging note <context> Adds context; Sentinel re-checks the cited code
@apex-sentinel-staging pivot <why> Says the finding is wrong; Sentinel re-checks the cited code
@apex-sentinel-staging like Marks the finding as useful
@apex-sentinel-staging dislike <why> Marks it as not useful, so it is not raised again

On this conversation, comment @apex-sentinel-staging review to run a full review once again.

@thymikee

Copy link
Copy Markdown
Member Author

Addressing the review at 8516300; final head is now 55f5b877e31a676107f47d5457d2d5179a317b83.

1. Timeout-removal regression through the harness entry (was: self-rejecting capture test).
The context runCli override and the scenario-internal export are gone. The Android harness is now constructible with its existing runner injection — createAndroidLiveHarness({ runCli }) in live-harness.ts, with createAndroidLiveAssertions(harness) binding the assertion helpers to that harness — and the Home/Recents lane runs as a registered scenario: createHomeAndRecentsRestorationScenario(steps) executed via harness.runScenario in live-automation-scenario.test.ts (no manual currentScenario faking). waitForSurfaceChange now takes the bound capturePng, so the default capture's timeoutMs: Math.min(remaining, 5000) reaches the harness's CLI runner.

The scripted CLI double observes and enforces the forwarded timeout like a real runner: a capture would finish after 60 s, but a forwarded options.timeoutMs kills it first and returns a failure. With the timeout, the wedged-capture scenario fails at the 10 s wait deadline with capture N failed, and the recorded per-attempt timeouts show the remaining deadline (capped at 5 s, shrinking across attempts: 5000 → 4750). Mutant check: removing timeoutMs from the default capture makes both scenario tests fail (expected 'undefined' to be 'number' on the observed timeout; the wedged test's rejection no longer matches capture N failed) — verified locally, then restored. The success path also asserts every Home/Recents wait attempt received a bounded numeric timeout, and both waits still pass only after the delayed captures differ (single-capture route still fails them).

2. Ten consecutive hosted Android smoke passes at the unchanged head.
Workflow run 44406428798 (android.yml, event pull_request, head_sha 55f5b877e31a676107f47d5457d2d5179a317b83): the initial Smoke Tests job plus ten consecutive reruns of that job at the unchanged head — 11 executions, all success:

# job attempt conclusion Home/Recents waits
1 https://github.com/callstack/agent-device/actions/runs/44406428798/job/135162841640 success capture Android Home surface (attempt 1) status 0, capture Android Recents surface (attempt 1) status 0
2 .../job/135166033700 success same, pass 1 / fail 0
3 .../job/135169807283 success same
4 .../job/135173730913 success same
5 .../job/135177643973 success same
6 .../job/135180726313 success same
7 .../job/135184007531 success same
8 .../job/135187535422 success same
9 .../job/135190285281 success same
10 .../job/135193942664 success same
11 .../job/135197493388 success same

Every attempt's job log and android-artifacts are retained (per-attempt proof.txt + logs + artifacts, kept locally at /tmp/ad-smoke-55f5b877/01..11). Each proof shows ✔ live Android emulator fixture E2E with pass 1 / fail 0, the step-history wait steps capture Android Home surface (attempt N) and capture Android Recents surface (attempt N) with status 0 (both transition waits reached and passed their pixel comparisons — three distinct md5s for foreground.png/home.png/recents.png per attempt), and home-recents-restoration: true in coverage-report.json (fixture restoration after Home/Recents).

Local gates at 55f5b877: pnpm check:affected --run --head 55f5b877e31a676107f47d5457d2d5179a317b83 (receipt .tmp/validation/run-S084nc, exactCommit=true) — format, lint, typecheck, fallow, layering, di-seams, build, package, integration-node, macos-coverage, vitest-related all passed; the unit suite passed 20613/20627 with only the known host-load 5 s-timeout flakes in scripts/__tests__/release-publish.test.ts / test/repo-guards/release-assets.test.ts (pass solo; same failures occur on unchanged origin/main under the same host load). Focused: 27/27 across the four android-emulator-e2e suites (9 new tests), live-device-e2e-runtime 14/14 via node --test; pnpm typecheck, pnpm format, oxlint, fallow audit clean.

@thymikee
thymikee merged commit b566dca into main Nov 19, 2026
30 checks passed
@thymikee
thymikee deleted the t3/android-transition-wait branch November 19, 2026 06:47
thymikee added a commit that referenced this pull request Nov 24, 2026
… Home (#4990) (#5045)

The Android smoke lane failed at the Home foreground assertion on three
unrelated 0.22 PRs (jobs 137197315801, 137220955468, 137350879830). Each
run shows the same ordering: `home` finished after 55-121 ms (one injected
keyevent), the next `appstate` read started 90-193 ms later, answered in
193-443 ms, and still named com.callstack.agentdevicelab/MainActivity.
The retained failed-step evidence for run 45068801264 shows
`topResumedActivity=NexusLauncherActivity` about 1.5 s after the keyevent,
so Home did happen; the scenario read the foreground while WindowManager
was still resuming the launcher.

#4716 added the bounded wait for the pixel transition and kept the single
unconditional foreground read. `assertHomeAndRecentsRestoration` now waits
at that observation with `waitForForegroundLeaves` (same owner, deadline,
poll and per-read bound as `waitForSurfaceChange`), and the lane reads
pixels only once the device itself reports the foreground left the fixture.
A foreground that never leaves fails at the deadline with its last
observation; no sleep, no assertion retry, no relaxed check.

Coverage runs through the harness entry: a scripted device that keeps the
foreground stale for the first reads passes only via the wait (the
pre-fix route fails it with the hosted notStrictEqual signature), and a
foreground that never transitions fails the lane before any Home-surface
capture. The wait owns delayed reads, read failures, reads that answer no
package, reads bounded to the remaining deadline, and late observations.
thymikee added a commit that referenced this pull request Nov 24, 2026
… Home (#4990) (#5045)

The Android smoke lane failed at the Home foreground assertion on three
unrelated 0.22 PRs (jobs 137197315801, 137220955468, 137350879830). Each
run shows the same ordering: `home` finished after 55-121 ms (one injected
keyevent), the next `appstate` read started 90-193 ms later, answered in
193-443 ms, and still named com.callstack.agentdevicelab/MainActivity.
The retained failed-step evidence for run 45068801264 shows
`topResumedActivity=NexusLauncherActivity` about 1.5 s after the keyevent,
so Home did happen; the scenario read the foreground while WindowManager
was still resuming the launcher.

#4716 added the bounded wait for the pixel transition and kept the single
unconditional foreground read. `assertHomeAndRecentsRestoration` now waits
at that observation with `waitForForegroundLeaves` (same owner, deadline,
poll and per-read bound as `waitForSurfaceChange`), and the lane reads
pixels only once the device itself reports the foreground left the fixture.
A foreground that never leaves fails at the deadline with its last
observation; no sleep, no assertion retry, no relaxed check.

Coverage runs through the harness entry: a scripted device that keeps the
foreground stale for the first reads passes only via the wait (the
pre-fix route fails it with the hosted notStrictEqual signature), and a
foreground that never transitions fails the lane before any Home-surface
capture. The wait owns delayed reads, read failures, reads that answer no
package, reads bounded to the remaining deadline, and late observations.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-human Valid work that needs human implementation, judgment, or maintainer merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Android emulator smoke: Home and Recents screenshot comparisons fail intermittently

1 participant